What is get-stdin?
The get-stdin package is a simple utility that allows you to easily read stdin as a string or buffer in Node.js. It's useful for command-line tools that need to process input piped to them from the command line.
What are get-stdin's main functionalities?
Read stdin as a string
This feature allows you to read the standard input (stdin) as a string. It returns a promise that resolves with the entire input when the stdin stream ends.
const getStdin = require('get-stdin');
getStdin().then(input => {
console.log(input);
});
Read stdin as a buffer
This feature allows you to read the standard input (stdin) as a buffer. It returns a promise that resolves with the entire input as a buffer when the stdin stream ends.
const getStdin = require('get-stdin');
getStdin.buffer().then(input => {
console.log(input);
});
Other packages similar to get-stdin
raw-body
The raw-body package is similar to get-stdin but is more focused on parsing HTTP request bodies and provides more options for limiting size, setting character encoding, and handling errors.
concat-stream
Concat-stream is a writable stream that concatenates all the data from a stream and calls a callback with the result. It can be used in a similar way to get-stdin for collecting stream data, but it is not limited to stdin and does not return a promise.
get-stream
Get-stream is a utility that turns a stream into a string or buffer. It is very similar to get-stdin but works with any stream, not just stdin, and offers more options for handling the stream data.
get-stdin
Easier stdin
Install
npm install --save get-stdin
Example
var stdin = require('get-stdin');
stdin(function (data) {
console.log(data);
});
$ echo unicorns | node example.js
License
MIT © Sindre Sorhus